// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
import Dashboard from '@/views/Dashboard.vue'
import PersonalCenter from '@/views/PersonalCenter.vue'
import Permission from '@/views/Permission.vue'
import Organization from '@/views/Organization.vue'
import Statistics from '@/views/Statistics.vue'
import Logs from '@/views/Logs.vue'
import Positions from '@/views/Positions.vue'
import Recruitment from '@/views/Recruitment.vue'
import Personnel from '@/views/Personnel.vue'
import Onboarding from '@/views/personnel/Onboarding.vue'
import Transfer from '@/views/personnel/Transfer.vue'
import Leave from '@/views/personnel/Leave.vue'
import PendingList from '@/views/recruitment/PendingList.vue'
import EmployedList from '@/views/recruitment/EmployedList.vue'
import OnboardedList from '@/views/recruitment/OnboardedList.vue'

const routes = [
    {
        path: '/',
        redirect: '/dashboard'
    },
    {
        path: '/dashboard',
        name: 'Dashboard',
        component: Dashboard,
        meta: { title: '控制面板' }
    },
    {
        path: '/personal-center',
        name: 'PersonalCenter',
        component: PersonalCenter,
        meta: { title: '个人中心' }
    },
    {
        path: '/permission',
        name: 'Permission',
        component: Permission,
        meta: { title: '权限管理' }
    },
    {
        path: '/organization',
        name: 'Organization',
        component: Organization,
        meta: { title: '组织管理' }
    },
    {
        path: '/statistics',
        name: 'Statistics',
        component: Statistics,
        meta: { title: '数据统计' }
    },
    {
        path: '/logs',
        name: 'Logs',
        component: Logs,
        meta: { title: '操作日志' }
    },
    {
        path: '/positions',
        name: 'Positions',
        component: Positions,
        meta: { title: '职位设置' }
    },
    {
        path: '/recruitment',
        name: 'Recruitment',
        component: Recruitment,
        meta: { title: '人才招聘' },
        redirect: '/recruitment/pending',
        children: [
            {
                path: 'pending',
                name: 'PendingList',
                component: PendingList,
                meta: { title: '待面试' }
            },
            {
                path: 'employed',
                name: 'EmployedList',
                component: EmployedList,
                meta: { title: '已录用' }
            },
            {
                path: 'onboarded',
                name: 'OnboardedList',
                component: OnboardedList,
                meta: { title: '已入职' }
            }
        ]
    },
    {
        path: '/personnel',
        name: 'Personnel',
        component: Personnel,
        meta: { title: '人事管理' },
        redirect: '/personnel/onboarding',
        children: [
            {
                path: 'onboarding',
                name: 'Onboarding',
                component: Onboarding,
                meta: { title: '入职管理' }
            },
            {
                path: 'transfer',
                name: 'Transfer',
                component: Transfer,
                meta: { title: '调动管理' }
            },
            {
                path: 'leave',
                name: 'Leave',
                component: Leave,
                meta: { title: '离职管理' }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title ? `${to.meta.title} - HRM系统` : 'HRM系统'
    next()
})

export default router